﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QDT.Common;

namespace QDT.Core.Projects
{
    public class ProjectFeildException:Exception
    {
         public ProjectFeildException():base()
        {
            StatusCode = ProjectFeildException.Unknow;
        }

        public ProjectFeildException(string message):base(message)
        {
            StatusCode = ProjectFeildException.Unknow;
        }

        public ProjectFeildException(string message, Exception inner):base(message,inner)
        {
            StatusCode = ProjectFeildException.Unknow;
        }

        public ProjectFeildException(int statusCode, ProjectFeild projectFeild)
        {
            StatusCode = statusCode;
            ProjectFeild = projectFeild;
        }

        public ProjectFeildException(int statusCode)
            : this(statusCode, null)
        {
            
        }

        public int StatusCode { get; set; }

        public ProjectFeild ProjectFeild { get; set; }

        /// <summary>
        /// 未知的异常
        /// </summary>
        public const int Unknow = 0;

        /// <summary>
        /// 存在相关的项目信息,不能删除
        /// </summary>
        public const int DuplicateName = 1;

        public override string Message
        {
            get
            {
                switch(StatusCode) {
                    case DuplicateName:
                        return "重复的名称 {0}.".FormatWith(ProjectFeild == null ? "" : ProjectFeild.Name);
                    default:
                        return base.Message;
                }
            }
        }
    }
}
